package pres.lnk.learn.designpattern.d_builder;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>用户点餐（复杂产品建造模型）</p>
 * @Author lnk
 * @Date 2018/2/1
 */
public class Meal {
    private List<Item> items = new ArrayList<>();

    /**
     * 点餐
     * @param item
     */
    public void addItem(Item item){
        items.add(item);
    }

    /**
     * 计算金额
     * @return
     */
    public float getCost(){
        float cost = 0.0f;
        for (Item item : items) {
            cost += item.price();
        }
        return cost;
    }

    /**
     * 打印点餐列表
     */
    public void showItems(){
        for (Item item : items) {
            System.out.print("Item : "+item.name());
            System.out.print(", Packing : "+item.packing().pack());
            System.out.println(", Price : "+item.price());
        }
    }
}
